<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>waf日志中心</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote layui-text">
            日志字段说明:1. <a href="#" target="_blank">日志字段说明</a>
                       2. <a href="#" target="_blank">日志查询功能说明</a>
                       3. <a href="/page/xwaf/waf_riskip.html" target="_blank">IP情报查询</a> 4.双击表格中的行显示详情
            <a class="layui-btn" style="float:right" href="javascript:location.replace(location.href);" title="刷新">
              <i class="layui-icon">&#xe669;</i></a>
        </blockquote>
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">应用名</label>
                            <div class="layui-input-inline" style="width:130px">
                                <input type="text" name="appname" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">域名</label>
                            <div class="layui-input-inline" style="width:130px">
                                <input type="text" name="serverName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">日志类型</label>
                            <div class="layui-input-inline" style="width:130px">
                              <select name="logType" lay-filter="logType">
                                <option value="" selected="">全部</option>
                                <option value="waf">入侵检测</option>
                                <option value="reqlimit">防刷限流</option>		
                                <option value="bwlist">黑白名单</option>		
                              </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">攻击类型</label>
                            <div class="layui-input-inline" style="width:130px">
                              <select name="attackType" lay-filter="attackType">
                                <option value="" selected="">全部</option>
                                <option value="WHITE_IP">IP白名单</option>
                                <option value="BAD_IP">封禁IP</option>	
                                <option value="RISK_IP">威胁IP</option>	
                                <option value="BLACK_IP">IP黑名单</option>
                                <option value="WHITE_URL">URL白名单</option>
                                <option value="WHITE_UA">UA白名单</option>
                                <option value="DENY_COOKIE">CSRF攻击</option>
                                <option value="DENY_URI">URL扫描</option>
                                <option value="DENY_ARGS">参数注入</option>
                                <option value="DENY_UA">UA扫描器</option>
                                <option value="DENY_POSTDATAS">POST注入</option>	
                                <option value="URL_TooLong">URL长度限制</option>	
                                <option value="IPURI_LIMIT">IpUrl限流</option>
                                <option value="IP_LIMIT">单IP限流</option>
                                <option value="UA_LIMIT">UA限流</option>
                                <option value="RF_LIMIT">Reffer限流</option>
                                <option value="CIP_LIMIT">C段IP限流</option>
                                <option value="ALL_LIMIT">总Qps限流</option>
                                <option value="RISK_IP_LIMIT">威胁IP限流</option>
                                <option value="URL_IP_LIMIT">自定义URL,IP限流</option>
                                <option value="URL_CIP_LIMIT">自定义URL,C段IP限流</option>
                                <option value="URL_RF_LIMIT">自定义URL,reffer限流</option>
                                <option value="URL_ARGS_LIMIT">自定义URL,args限流</option>
                                <option value="URL_UA_LIMIT">自定义URL,UA限流</option>
                                <option value="URL_ALL_LIMIT">自定义URL,总Qps</option>	
                              </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">攻击IP</label>
                            <div class="layui-input-inline" style="width:130px">
                                <input type="text" name="clientIp" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">URL</label>
                            <div class="layui-input-inline" style="width:130px">
                                <input type="text" name="reqUrl" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">userAgent</label>
                            <div class="layui-input-inline" style="width:130px">
                                <input type="text" name="userAgent" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" id="timeSelect">
                            <label class="layui-form-label">时间范围</label>
                            <div class="layui-input-inline" style="width:150px">
                              <input type="txt" id="starttime" name="starttime" value="" class="layui-input textboxtime" placeholder="开始时间" />
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width:150px">
                              <input type="txt" id="endtime" name="endtime" value="" class="layui-input textboxtime" placeholder="结束时间" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <table class="layui-table" lay-size="lg" id="currentTableId" lay-filter="currentTableId"></table>

    </div>
</div>
<script type="text/html" id="toolbarDemo">
</script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
            laydate = layui.laydate;

      	var urls = location.search;
      	if (urls.indexOf("?") != -1) {
      		urls = urls.replace("?", "&");
      	}
        table.render({
            elem: '#currentTableId',
            url: '/metric/v1/DumpLog?key=appName,serverName,serverIp,logType,clientIp,reqUrl,attackType,blockInfo,userAgent,hTime'+urls,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],
            cols: [[
                //{type: "checkbox", width: 50},
                {field: 'appName',title: '应用名',hide:true},
                {field: 'serverName',title: '域名', sort: true},
                {field: 'serverIp',title: '接入IP', sort: true,hide:true},
                {field: 'logType',width:100, title: '类型', sort: true},
                {field: 'attackType',width:130, title: '攻击类型', sort: true},
                {field: 'clientIp',title: '攻击IP', sort: true},
                {field: 'reqUrl', title: '攻击URL', sort: true},
                {field: 'blockInfo',title: '拦截信息', sort: true},
                {field: 'ruleTag', title: '触发规则', sort: true,hide:true},
                {field: 'userAgent', title: 'userAgent', sort: true},
                {field: 'hTime', title: '时间'}
            ]],
            limits: [50, 100, 200],
            limit: 50,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //layer.alert(result, {
            //    title: '最终的搜索信息'
            //});
          	var urls = location.search;
          	if (urls.indexOf("?") != -1) {
          		urls = urls.replace("?", "&");
          	}

            //执行搜索重载
            table.reload('currentTableId', {
                //page: {
                //    curr: 1,
                //    limit:50
                //},
                method:'POST',
                url: '/metric/v1/DumpLog?key=appName,serverName,serverIp,logType,clientIp,reqUrl,attackType,blockInfo,userAgent,ruleTag,hTime'+urls,
                contentType: 'application/json',
                where: data.field,
                done: function(res, curr, count){
                  //console.log(res);
                  //this.where={};
                  //不清空，有问题：搜索条件会保留
                  //清空，  有问题：分页的时候没有搜索条件了,分页会受到影响
                  //https://copyfuture.com/blogs-details/20200729003153292ltjtf01kvp048gr
                }
            }, 'data');

            return false;
        });

        //行单击事件（双击事件为：rowDouble）
        table.on('rowDouble(currentTableId)', function(obj){
          var data = obj.data;
          
          layer.alert(JSON.stringify(data), {
            title: '当前行数据：'
          });
          
          //标注选中样式
          obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });

        //日期范围
        //laydate.render({
        //  elem: '#timeSelect'
        //  ,type: 'datetime'
        //  //设置开始日期、日期日期的 input 选择器
        //  //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
        //  ,range: ['#starttime','#endtime']
        //});

        lay('.textboxtime').each(function(){
          laydate.render({
            elem: this,
        	  type: 'datetime',
            format: 'yyyy-MM-ddTHH:mm:ss'
          });
        });

        //监听表格复选框选择
        //table.on('checkbox(currentTableFilter)', function (obj) {
         //   console.log(obj)
        //});
    });
</script>

</body>
</html>